<template>
	<view class="main" :class="{'hiddens':isShow}">

		<view class="mask" v-if="isShow">
			<view class="content">
				<view class="title">
					温馨提示
				</view>
				<view class="text">
					欢迎使用 GROWLA为了更好的保护您的权益,同时遵守相关监管要求,我们将通过《GROWLA隐私政策》向您说明我们会如何收集,存储,保护和使用您的信息,请您认证阅读以下协议

				</view>
				<view class="text">
					<text @click="toprovacy">《GROWLA隐私政策》</text>和<text @click="toterms">《GROWLA服务条款》</text>
				</view>
				<view class="btn">
					<view class="no" @click="exit">
						不同意
					</view>
					<view class="ok" @click="ok">
						同意
					</view>
				</view>
			</view>
		</view>
		<view class="top">
			<!-- <uni-search-bar cancelButton="none" class="seach" @focus="focus" :placeholder="$t('index.seachPlaceholder')"></uni-search-bar> -->
			<view class="search" @click="focus">
				<image src="../../static/image/search.png" mode=""></image>
				<text>{{$t('index.seachPlaceholder')}}</text>
			</view>
			<swiper class="swiper-box" @change="change" :autoplay="true" :circular="true" :indicator-dots="true"
				indicator-color="rgba(255, 255, 255, .5)" indicator-active-color="#ffffff">
				<swiper-item v-for="(item ,index) in data.banner" :key="index">
					<view class="swiper-item">
						<image :src="item" mode=""></image>
					</view>
				</swiper-item>
			</swiper>
		</view>
		<view class="clazz-content">
			<view class="tab">

				<uni-segmented-control class="tabs" :current="index" :values="tabList" styleType="text"
					activeColor="#4DBEC1" @clickItem="changeIndex"></uni-segmented-control>

				<image src="../../static/image/Group.png" mode="" @click="toClazz"></image>

			</view>
			<courseList v-if="data.course" :list="data.course[nums]"></courseList>
		</view>
		<view class="recommended-content">
			<view class="title">
				<text class="recommend">{{ $t('index.recommendedCourse') }}</text>
				<view class="more">
					<text>{{ $t('index.more') }}</text>
					<image src="../../static/image/more.png" mode="" @click="toMore"></image>
				</view>
			</view>
			<courseList :list="data.tuijian"></courseList>
		</view>
	</view>
</template>

<script>
	import courseList from "./components/courseList.vue"
	export default {
		data() {
			return {
				data: {},
				current: 0,
				index: 0,
				isShow: true
				// tabList: ["儿童发展", "班级管理", "家长教育", "心理学"]
			}
		},
		components: {
			courseList
		},
		computed: {
			tabList() {
				let list = []
				if (this.data.category) {
					this.data.category.forEach(ele => {
						list.push(ele.name)
					})
				}
				return list
			},
			nums() {
				let num = 0
				if (this.data.category) {
					num = this.data.category[this.index].id

				}
				return num
			}
			// locales() {
			// 	return [
			// 		{
			// 			text: this.$t('locale.en'),
			// 			code: 'en'
			// 		},
			// 		{
			// 			text: this.$t('locale.zh-hans'),
			// 			code: 'zh-Hans'
			// 		}
			// 	]
			// }
		},
		onLoad() {
			console.log(uni.getStorageSync('first'))
			this.isShow = !(uni.getStorageSync('first') == 1)
			this.getData()
		},
		methods: {
			toprovacy(){
				uni.navigateTo({
					url:"/pages/privacyPolicy/privacyPolicy"
				})
			},
			toterms(){
				uni.navigateTo({
					url:"/pages/serviceTerms/serviceTerms"
				})
			},
			exit() {
				if (plus.os.name.toLowerCase() === 'android') {
					plus.runtime.quit();
				} else {
					const threadClass = plus.ios.importClass("NSThread");
					const mainThread = plus.ios.invoke(threadClass, "mainThread");
					plus.ios.invoke(mainThread, "exit");
					// 或者如下
					 plus.ios.import('UIApplication').sharedApplication().performSelector('exit');
				}
			},
			ok() {
				uni.setStorageSync('first',1)
				this.isShow = false
			},
			getData() {
				this.$httpRequest({
					url: "app/api/indexApp.php",
					method: "POST",
					data: {
						service: "moodle_mobile_app"
					}
				}).then(res => {
					this.data = res
				})
			},
			toMore() {
				uni.navigateTo({
					url: "/pages/clazzList/clazzList?path=clazz"
				})
			},
			focus() {
				uni.navigateTo({
					url: "/pages/scarch/scarch"
				})
			},
			change(e) {
				this.current = e.detail.current;
			},
			changeIndex(e) {
				this.index = e.currentIndex
			},
			toClazz() {
				uni.switchTab({
					url: "/pages/clazz/clazz"
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	.hiddens {
		overflow: hidden;
	}

	.main {
		width: 100%;
		height: 100%;
		background-color: #F5F6FA;

		.mask {
			position: fixed;
			left: 0;
			top: 0;
			width: 100%;
			height: 100%;
			background: rgba(0, 0, 0, .4);
			z-index: 9999;
			display: flex;
			justify-content: center;
			align-items: center;

			.content {
				position: relative;
				width: 540rpx;
				height: 534rpx;
				background-color: #fff;
				padding: 0 24rpx;
				border-radius: 16rpx;
				font-size: 28rpx;
				font-family: PingFang SC-Medium, PingFang SC;
				font-weight: 400;
				color: #0F1826;

				.title {
					text-align: center;
					font-size: 36rpx;
					font-family: PingFang SC-Semibold, PingFang SC;
					font-weight: 600;
					color: #0F1826;
					margin: 40rpx 0;
				}

				text {
					color: #4DBEC1;
				}

				.btn {
					position: absolute;
					left: 0;
					bottom: 0;
					border-top: 1rpx solid #EBEDF0;
					width: 100%;
					height: 84rpx;
					display: flex;
					align-items: center;
					text-align: center;
					font-size: 30rpx;
					font-weight: 500;
					font-family: PingFang SC-Medium, PingFang SC;
					line-height: 84rpx;

					.no {
						width: 50%;
						color: #6E7580;
						border-right: 1rpx solid #ebedf0;
					}

					.ok {
						flex: 1;
						color: #4DBEC1;
					}
				}
			}
		}

		.top {
			width: 750rpx;
			height: 520rpx;
			background: linear-gradient(180deg, #4DBEC1 0%, rgba(77, 190, 193, 0) 100%);
			border-radius: 0px 0px 0px 0px;
			overflow: auto;

			.search {
				width: 90%;
				margin: 0 auto;
				height: 56rpx;
				line-height: 56rpx;
				text-align: center;
				background-color: #FFFFFF;
				font-size: 24rpx;
				font-family: PingFang TC-Regular, PingFang TC;
				font-weight: 400;
				color: #A9AFB8;
				margin: 104rpx auto 24rpx;
				display: flex;
				justify-content: center;
				align-items: center;
				border-radius: 28rpx;

				text {
					height: 56rpx;
					line-height: 56rpx;
					display: inline-block;
				}

				image {
					width: 40rpx;
					height: 40rpx;
				}
			}

			.seach {
				margin: 104rpx auto 24rpx;
				width: 686rpx;
			}

			.swiper-box {
				width: 90%;
				height: 276rpx;
				border-radius: 20rpx;
				margin: 0 auto;

				.swiper-item {
					text-align: center;
					line-height: 206rpx;
					height: 100%;
					background-color: #123132;
					border-radius: 20rpx;

					image {
						width: 100%;
						height: 100%;
						border-radius: 20rpx;
					}
				}
			}
		}

		.clazz-content {

			margin-bottom: 20rpx;
			background-color: #FFFFFF;
			border-bottom-right-radius: 20rpx;
			border-bottom-left-radius: 20rpx;
			overflow: hidden;

			.tab {
				display: flex;
				// justify-content: space-around;		
				align-items: center;
				margin: 32rpx 0;

				image {
					width: 32rpx;
					height: 32rpx;
					margin-left: 14rpx;
				}

				.tabs {
					width: 90%;

					::v-deep .segmented-control__text {
						font-size: 28rpx !important;

					}
				}
			}
		}

		.recommended-content {
			margin-bottom: 20rpx;
			background-color: #FFFFFF;
			border-top-right-radius: 20rpx;
			border-top-left-radius: 20rpx;
			overflow: hidden;

			.title {
				display: flex;
				justify-content: space-between;
				align-items: center;
				width: 90%;
				margin: 30rpx auto;

				.recommend {
					font-size: 32rpx;
					font-weight: 500;
					color: #0F1826;
				}

				.more {
					width: 110rpx;
					height: 52rpx;
					border-radius: 60rpx;
					opacity: 1;
					border: 2rpx solid #C9CED6;
					display: flex;
					justify-content: center;
					align-items: center;

					text {
						font-size: 24rpx;
						color: #6E7580;
						// line-height: 52rpx;
					}

					image {
						width: 20rpx;
						height: 20rpx;
					}
				}
			}
		}
	}
</style>
